import {axios} from '../utils/request'
import {PIPELINE_MODULE} from "./_prefix";
import {MOCK} from "./_prefix";

/**
 * 新建流水线 POST
 * @param {*} payload
 * @returns
 */
export const addPipeline = async payload => {
    const {userId, pipelineName, features, label, machineLearningAlgorithm, trainParams} = payload;
    const res = await axios.post(`${PIPELINE_MODULE}`, {
        userId,
        pipelineName,
        features,
        label,
        machineLearningAlgorithm,
        trainParams,
    })
    return res
}

/**
 * 获取所有流水线
 * @param {*} payload
 * @returns
 */
export const getAllPipeline = payload => {
    const {userId} = payload;
    return axios.get(`${PIPELINE_MODULE}/?userId=${userId}`).then(res => {
    // return axios.get(`${MOCK}/ml/pipelines/all/:userId`).then(res => {
        return res;
    });
}
/**
 * 使用流水线
 * @param {*} payload
 * @returns
 */
export const usePipeline = payload => {
    const {pipelineId, fileId, modelName} = payload;
    return axios.post(`${PIPELINE_MODULE}/${pipelineId}?fileId=${fileId}&modelName=${modelName}`).then(res => {
    // return axios.post(`${MOCK}/ml/pipelines/:pipelineId`).then(res => {
        return res;
    });
}

/**
 * 删除流水线 GET
 * @param {*} payload
 * @returns
 */
export const deletePipeline = payload => {
    const {pipelineId} = payload;
    return axios.delete(`${PIPELINE_MODULE}/${pipelineId}`).then(res => {
    // return axios.delete(`${MOCK}/ml/pipelines/:pipelineId`).then(res => {
        return res;
    });
}